package com.itheima.duotai7;

public class Test {

    public static void main(String[] args) {
        useAnimal(new Dog());
        useAnimal(new Cat());
    }

    public static void useAnimal(Animal a){
        a.drink();
        a.eat();
        //想要看家
        //可能会产生 类型转换异常
        // 判断
        if(a instanceof Dog){
            Dog dog = (Dog) a;
            dog.watchHome();
        }



    }
}
abstract class Animal{
    public void drink(){
        System.out.println("动物喝水");
    }
    public abstract  void eat();
}
class Dog extends Animal{

    @Override
    public void eat() {
        System.out.println("狗吃骨头");
    }
    public void watchHome(){
        System.out.println("狗看家");
    }
}class Cat extends Animal{

    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }
}